<template>
  <div class="app-container">
    <el-card class="box-card" style="margin-bottom: 20px">
      <div style="width: 100%; display: flex" v-if="!loading">
        <div
          style="
            width: 20%;
            display: flex;
            justify-content: center;
            align-items: center;
          "
        >
          <el-tag>{{ srmxStatus.withdrawalStatusTiList[form.status] }}</el-tag>
        </div>
        <div style="width: 60%; display: flex; justify-content: space-around">
          <div>
            <div style="padding: 10px 0">
              <span>提现时间:</span><span>{{ form.createTime }}</span>
            </div>
            <div style="padding: 10px 0">
              <span>提现批次号:</span><span>{{ form.tiNo }}</span>
            </div>
            <div style="padding: 10px 0">
              <span>提现金额:</span><span> ¥ {{ form.totalMoeny }}</span>
            </div>
          </div>
          <div>
            <div style="padding: 10px 0">
              <span>账户:</span><span>{{ form.account }}</span>
            </div>
            <div style="padding: 10px 0">
              <span>银行卡号:</span><span>{{ form.bank }}</span>
            </div>
            <div style="padding: 10px 0">
              <span>开户行:</span><span>{{ form.openBank }}</span>
            </div>
          </div>
        </div>
        <div style="width: 20%" v-if="form.reason">
          <div>
            <span>原因:</span><span>{{ form.reason }}</span>
          </div>
        </div>
      </div>
    </el-card>
    <el-table
      v-loading="loading"
      :data="slmxList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="员工编号" align="center" prop="ygNo" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="手机号" align="center" prop="tel" />
      <el-table-column label="项目名称" align="center">
        <template slot-scope="scope">
          {{ "【" + scope.row.brandName + "】-" + scope.row.positionName }}
        </template>
      </el-table-column>
      <el-table-column label="返费金额" align="center" prop="money" />
      <el-table-column label="寻访顾问" align="center" prop="userName" />
      <el-table-column
        label="PM"
        align="center"
        prop="positionResponsiblePerson"
      />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="状态" prop="backStatus">
          <el-radio-group v-model="form.backStatus">
            <el-radio label="2">通过</el-radio>
            <el-radio label="3" v-if="restate">未通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="返费金额" prop="money" v-if="form.backStatus == 2">
          <el-input-number
            v-model="form.money"
            :precision="2"
          ></el-input-number>
        </el-form-item>
        <el-form-item label="原因" prop="reason" v-if="form.backStatus == 3">
          <el-input
            v-model="form.reason"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import { delSlmx, repeatUpdateSlmx, updateSlmx } from "@/api/system/slmx";
import { getTi, listSlmx } from "@/api/system/ti";
import { srmxStatus } from "@/utils/data.js";

export default {
  name: "Slmx",
  data() {
    return {
      srmxStatus,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      slmxList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tiId: 6,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        money: [{ required: true, message: "金额不能为空", trigger: "blur" }],
        reason: [{ required: true, message: "原因不能为空", trigger: "blur" }],
      },
      restate: true,
    };
  },
  created() {
    this.queryParams.tiId = this.$route.query.tiId;
    this.getList();
    this.getTiList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listSlmx(this.queryParams).then((response) => {
        this.slmxList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getTiList() {
      getTi(this.queryParams.tiId).then((response) => {
        this.form = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        backStatus: "2",
        money: null,
        reason: null,
        slmxId: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    listTab() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.slmxId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    /** 修改按钮操作 */
    handleUpdate(row, state) {
      this.reset();
      this.form.slmxId = row.slmxId;
      this.form.money = row.money;
      this.restate = state;
      this.open = true;
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          const data = this.form;
          const flag = this.restate;
          let backStatus = this.form.backStatus;
          let money = this.form.money;
          let tigs =
            backStatus == "2"
              ? "金额为：" + money + "元《请核对金额是否填写正确》"
              : "请详细明确原因";
          this.$modal
            .confirm(tigs)
            .then(function () {
              if (flag) {
                return updateSlmx(data);
              } else {
                return repeatUpdateSlmx(data);
              }
            })
            .then(() => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const slmxIds = row.slmxId || this.ids;
      this.$modal
        .confirm('是否确认删除编号为"' + slmxIds + '"的数据项？')
        .then(function () {
          return delSlmx(slmxIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/slmx/export",
        {
          ...this.queryParams,
        },
        `slmx_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
